using MediatR;
using MeetingManagement.Application.Commands.MeetingRooms.CreateMettingRoom;
using MeetingManagement.Application.Commands.MeetingRooms.DeleteMeetingRoom;
using MeetingManagement.Application.Commands.MeetingRooms.UpdateMeetingRoom;
using MeetingManagement.Application.Queries.MeetingRooms;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace MeetingManagement.WebApi.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    [Authorize]
    public class MeetingRoomsController : ControllerBase
    {
        private readonly IMediator _mediator;
        public MeetingRoomsController(IMediator mediator) { _mediator = mediator; }

        [HttpGet]
        public async Task<IActionResult> GetAll() => Ok(await _mediator.Send(new GetAllMeetingRoomsQuery()));

        [HttpPost]
        [Authorize(Roles = "Admin")]
        public async Task<IActionResult> Create([FromBody] CreateMeetingRoomCommand cmd)
            => Ok(await _mediator.Send(cmd));

        [HttpPut]
        [Authorize(Roles = "Admin")]
        public async Task<IActionResult> Update([FromBody] UpdateMeetingRoomCommand cmd)
            => Ok(await _mediator.Send(cmd));

        [HttpDelete("{id}")]
        [Authorize(Roles = "Admin")]
        public async Task<IActionResult> Delete(Guid id)
            => Ok(await _mediator.Send(new DeleteMeetingRoomCommand { Id = id }));
    }
}
